package com.example.travelservlet.city.service;

import com.example.travelservlet.city.repository.CityRepository;
import com.example.travelservlet.entity.City;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

@Service
public class CityServiceImpl implements CityService{
    @Autowired
    private CityRepository cityRepository;
    @Override
    public List<City> findCitiesByProId(String proId) {
        List<City> cities = cityRepository.findAllByProId(proId);
        return cities;
    }

    @Override
    public City findCityById(String cityId) {
        Optional<City> optional = cityRepository.findById(cityId);
        if(optional.isPresent()){
            City city = optional.get();
            return city;
        }else {
            System.out.print(cityId+"......................................................");
        }

        return null;
    }

    @Override
    public City findCityByName(String cityName) {
        City city = cityRepository.findCityByCityName(cityName);
        return city;
    }

    @Override
    public City createCity(City city) {
        City city1 = cityRepository.save(city);
        return city1;
    }

    @Override
    public List<City> findALL() {
        List<City> all = cityRepository.findAll();
        return all;
    }


}
